package com.ruoyi.web.controller.system;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysDoc;
import com.ruoyi.system.service.ISysDocService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文档Controller
 * 
 * @author ruoyi
 * @date 2025-09-01
 */
@RestController
@RequestMapping("/system/doc")
public class SysDocController extends BaseController
{
    @Autowired
    private ISysDocService sysDocService;

    /**
     * 查询文档列表
     */
    @PreAuthorize("@ss.hasPermi('system:doc:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDoc sysDoc)
    {
        startPage();
        List<SysDoc> list = sysDocService.selectSysDocList(sysDoc);
        return getDataTable(list);
    }

    /**
     * 导出文档列表
     */
    @PreAuthorize("@ss.hasPermi('system:doc:export')")
    @Log(title = "文档", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDoc sysDoc)
    {
        List<SysDoc> list = sysDocService.selectSysDocList(sysDoc);
        ExcelUtil<SysDoc> util = new ExcelUtil<SysDoc>(SysDoc.class);
        util.exportExcel(response, list, "文档数据");
    }

    /**
     * 获取文档详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:doc:query')")
    @GetMapping(value = "/{docId}")
    public AjaxResult getInfo(@PathVariable("docId") Long docId)
    {
        return success(sysDocService.selectSysDocByDocId(docId));
    }

    /**
     * 新增文档
     */
    @PreAuthorize("@ss.hasPermi('system:doc:add')")
    @Log(title = "文档", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDoc sysDoc)
    {
        return toAjax(sysDocService.insertSysDoc(sysDoc));
    }

    /**
     * 修改文档
     */
    @PreAuthorize("@ss.hasPermi('system:doc:edit')")
    @Log(title = "文档", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDoc sysDoc)
    {
        return toAjax(sysDocService.updateSysDoc(sysDoc));
    }

    /**
     * 删除文档
     */
    @PreAuthorize("@ss.hasPermi('system:doc:remove')")
    @Log(title = "文档", businessType = BusinessType.DELETE)
	@DeleteMapping("/{docIds}")
    public AjaxResult remove(@PathVariable Long[] docIds)
    {
        return toAjax(sysDocService.deleteSysDocByDocIds(docIds));
    }


    @PostMapping("/app_doc_list")
    public AjaxResult appDocList(){
        return sysDocService.appDocList();
    }
}
